using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Impact.Model.Service;
using StructureMap;

namespace Impact.Model.Objects
{
    public partial class Tag
    {

        /// <summary>
        /// Retrieves a list of all the articles that are using this Tag
        /// </summary>
        public ArticleCollection Articles
        {
            get
            {
                if ( articles == null )
                {

                    ITagService tagService = ObjectFactory.GetInstance<ITagService>();
                    ArticleTagCollection aTags = tagService.FetchArticleTags( this.TagId );
                    articles = new ArticleCollection();
                    foreach ( ArticleTag aTag in aTags )
                    {
                        Article article = new Article( aTag.ArticleId );
                        if ( article.Enabled )
                        {
                            articles.Add( article );
                        }
                    }
                }
                return articles;
            }
        }
        private ArticleCollection articles;

        /// <summary>
        /// Returns true if the tag passed in is a valid tag object that can be used
        /// </summary>
        public static bool IsValid( Tag tag )
        {
            return tag != null && tag.TagId > 0;
        }

        /// <summary>
        /// provides a user-friendly description of this object
        /// </summary>
        public override string ToString()
        {
            return this.Text;
        }

    }
}
